package com.qianxun.spider.monitor;

import com.qianxun.spider.Spider;
import com.qianxun.spider.config.SpiderBeanConfig;
import org.jsoup.Connection;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.Map;

/**
 * @author: huwei
 * @date: 2020/6/28 15:06
 * @version: 1.0.0
 */
public interface SpiderMonitor {

    /**
     * 请求之前
     * @param connection
     * @param spiderBeanConfig
     * @param spider
     * @param localData
     */
    void requestBefore(Connection connection ,SpiderBeanConfig spiderBeanConfig, Spider spider, Spider.ThreadLocalData localData);

    /**
     * 请求之后
     * @param connection
     * @param spiderBeanConfig
     * @param spider
     * @param localData
     */
    void requestAfter(Connection connection , SpiderBeanConfig spiderBeanConfig , Spider spider, Spider.ThreadLocalData localData);

    /**
     * 请求发送错误
     * @param connection
     * @param spiderBeanConfig
     * @param spider
     * @param localData
     * @param throwable
     * @throws IOException
     */
    void requestError(Connection connection ,SpiderBeanConfig spiderBeanConfig, Spider spider, Spider.ThreadLocalData localData ,Throwable throwable);

    /**
     * 解析文件之前
     * @param document
     * @param spiderBeanConfig
     * @param spider
     * @param localData
     */
    void parseBefore(Document document ,SpiderBeanConfig spiderBeanConfig, Spider spider, Spider.ThreadLocalData localData);

    /**
     * 解析数据之后
     * @param document
     * @param spiderBeanConfig
     * @param parseData
     * @param spider
     * @param localData
     */
    void parseAfter(Document document , SpiderBeanConfig spiderBeanConfig , Map<String ,Object> parseData, Spider spider, Spider.ThreadLocalData localData);

    /**
     * 解析文件发生错误
     * @param document
     * @param spiderBeanConfig
     * @param throwable
     * @param spider
     * @param localData
     * @throws Throwable
     */
    void parseError(Document document ,SpiderBeanConfig spiderBeanConfig , Spider spider, Spider.ThreadLocalData localData,Throwable throwable);

    /**
     * 关闭通知
     * @param spiderBeanConfig
     */
    void close(SpiderBeanConfig spiderBeanConfig);
}
